<script type="text/javascript" src="<?php echo base_url(); ?>/public/js/jquery.js"></script>

<script src="<?php echo base_url(); ?>public/js/jquery.js"></script>
<script src="<?php echo base_url(); ?>public/js/jquery.tablesorter.min.js"></script>
<h2>My Subusers</h2>
<h3>Permissions:</h3>
<div id = "subusers">

<table id="sub" class="tablesorter"><thead class = "forms">
<tr><th>Sub-user</th><th>Can Edit Questions</th><th>Can Invite Respondents</th><th>Can View report</th><th>Can End Survey</th></tr></thead><tbody>
<?php foreach($subuser->result() AS $list){ ?>
		<tr><td><?php echo $list->subuser;?></td>
		<?php $i = 1;?>
		<td><?php if($list->edit_questions){
				echo form_checkbox(array('name' => 'edit_questions[]', 'value'=> 1, 'checked' => 1, 'disabled' => ''));
			} else {
				echo form_checkbox(array('name' => 'edit_questions[]', 'value'=> 0, 'checked' => 0, 'disabled' => ''));
			}
			
		;?></td>
		<td><?php if($list->invite_respondents){
				echo form_checkbox(array('name' => 'edit_questions[]', 'value'=> 1, 'checked' => 1, 'disabled' => ''));
			} else {
				echo form_checkbox(array('name' => 'edit_questions[]', 'value'=> 0, 'checked' => 0, 'disabled' => ''));
			}
		;?></td>
		<td><?php if($list->view_reports){
				echo form_checkbox(array('name' => 'edit_questions[]', 'value'=> 1, 'checked' => 1, 'disabled' => ''));
			} else {
				echo form_checkbox(array('name' => 'edit_questions[]', 'value'=> 0, 'checked' => 0, 'disabled' => ''));
			}
		;?></td>
		<td><?php if($list->end_survey){
				echo form_checkbox(array('name' => 'edit_questions[]', 'value'=> 1, 'checked' => 1, 'disabled' => ''));
			} else {
				echo form_checkbox(array('name' => 'edit_questions[]', 'value'=> 0, 'checked' => 0, 'disabled' => ''));
			}
		;?></td></tr>
		<?php $i++;?>
<?php	} ?>
<?php
	if ($subuser->num_rows == 0){
		echo "You have no subusers yet <br />";
	}
?><br>
</tbody>
</table>

<script type="text/javascript">
$(document).ready(function() 
    { 
        $("#sub").tablesorter(); 
    } 
);
</script>

</div><br>
<?php echo form_button(array('class' =>'reg', 'id' => 'button_edit', 'content' => 'Update Privileges')); ?>
<div id = "edit">
<table>
<thead><tr><th>Sub-user</th><th>Can Edit Questions</th><th>Can Invite Respondents</th><th>Can View report</th><th>Can End Survey</th></tr></thead>

<?php echo form_open('user/edit_privileges'); ?>
<?php $i= 1;?>
<?php foreach($subuser->result() AS $list){ ?>
	
	<tr><td><?php echo $list->subuser;?></td>

	<td><?php echo form_checkbox('edit_questions'.$i, 1, $list->edit_questions == 1 ? TRUE : FALSE); ?></td>
	<td><?php echo form_checkbox('invite_respondents'.$i, 1, $list->invite_respondents == 1 ? TRUE : FALSE); ?></td>
	<td><?php echo form_checkbox('view_reports'.$i, 1, $list->view_reports == 1 ? TRUE : FALSE); ?></td>
	<td><?php echo form_checkbox('end_survey'.$i, 1, $list->end_survey == 1 ? TRUE : FALSE); ?></td>
	<?php $i++;?>
<?php 	} ?></table>
<br>
<?php echo form_submit(array('class' => 'reg', 'value' => 'Update')); ?>
<?php echo form_close(); ?>
<br><br>
</div>

<script type="text/javascript">
	$('#edit').hide();
	$('#button_edit').show();
	$('#subusers').show();
  	$('#button_edit').click(function () {	
	$('#button_edit').fadeOut("fast");
	$('#subusers').fadeOut("fast");
	$('#edit').fadeIn("slow");
	});    
</script>

<?php echo form_button(array('id' => 'button_add', 'content' => 'Add More Subusers')); ?>
<div id = "groups">
<?php echo form_open('user/addsubuser');
echo "Add email:   "; echo form_input('subuser', 'Enter e-mail here'); echo "<br /><br />";
echo "Permissions to be granted: <br />";?>

<table>
<tr><?php echo form_hidden('edit_questions', 'FALSE'); ?>
<td><?php echo "Can Edit Questions: "; echo form_checkbox('edit_questions', 1, 0); ?></td>
<?php echo form_hidden('invite_respondents', 'FALSE'); ?>
<td><?php echo "Can Invite Respondents: "; echo form_checkbox('invite_respondents', 1, 0);?> </td>
<?php echo form_hidden('view_reports', 'FALSE'); ?>
<td><?php echo "Can View Reports: "; echo form_checkbox('view_reports', 1, 0);?> </td>
<?php echo form_hidden('end_survey', 'FALSE'); ?>
<td><?php echo "Can End Survey: "; echo form_checkbox('end_survey', 1, 0);?> </td>
</tr></table>

Invitation message:<br />

<input type="radio" id="template" name="mode" value="template"> Use an existing template</input><br/>
<input type="radio" id="custom" name="mode" value="custom"> Use a custom message</input><br/><br/>

<?php echo form_textarea(array('id' => 'body', 'name' => 'invitation_message', 'cols' => '70', 'rows' => '10', 'style' => 'display:none'), 'Insert a welcome message'); ?>

<div id="loaded" style="display:none">
Templates: <br/>
<?php foreach($templates as $template)
{
	echo "<input type=\"radio\" name=\"loaded_templates\" value=\"$template\"> Use this template</input><br/><textarea readonly cols=70 rows=10> $template</textarea><br/><br/>";	
}

?>

</div>
<br /><br />


<?php
echo form_submit('submit', 'Add'); echo "       ";
echo form_reset('reset', 'Reset');
?>
</div>
<script type="text/javascript">
	$('#groups').hide();
  	$("#button_add").click(function () {	
	$("#groups").toggle("fast");
	});    
</script>

<script src="<?php echo base_url(); ?>public/js/jquery.js"></script>
<script type="text/javascript">
	
	$(document).ready(function(){
		$("#template").change(function(){
			$("#body").hide('fast');
			$("#loaded").show('fast');
			
		});
		
		$("#custom").change(function(){
			$("#loaded").hide('fast');
			$("#body").val('Insert a welcome message');
			$("#body").show('fast');
		});
		
		$("input[name='loaded_templates']").change(function(){
				$("#body").val($("input[name='loaded_templates']:checked").val());
			});
	});
</script>
